package com.studerb.tasks;

import org.apache.commons.lang.math.RandomUtils;
import org.apache.log4j.Logger;

public class DummyTask extends AbstractTask<Void, Void> {
    private static final int MAX_LOOPS = 100;
    private Logger logger = Logger.getLogger(DummyTask.class);

    @Override public void init() {
        logger.debug("Task Init()");
        this.title = "Dummy Task";
        this.message = "Waiting...";
        this.determinable = true;
        this.connectionNeeded = true;
    }

    @Override protected Void doInBackground() throws Exception {
        logger.debug("Starting doInBackground");
        int count = 0;
        while(count < MAX_LOOPS){
            Thread.sleep(RandomUtils.nextInt(500));
            count++;
            setMessage("Count: " + count);
            setProgress(new Float((count / (MAX_LOOPS * 1.0))));
        }
        return null;
    }
}
